let ComponentLibraryCache = {};
/**
 * 用于定义和维护组件顶部菜单（组件库）中单个组件的信息
 * 字段信息在组件库上传时填入
 * package字段后台解压解析生成
 * 从组件库中选用组件需要进行组件定义 ComponentDefinition 的加载和初始化
 *
 */
class ComponentLibraryEntry {
	/**
	 * 组件库表主键
	 *
	 * @memberof ComponentLibraryEntry
	 */
	id = '';
	/**
	 * 组件名称（同时也是组件菜单显示名称）
	 *
	 * @memberof ComponentLibraryEntry
	 */
	name = '';
	/**
	 * 组件版本
	 *
	 * @memberof ComponentLibraryEntry
	 */
	version = '';
	/**
	 * @description 组件简介
	 * @memberof ComponentLibraryEntry
	 */
	introduction = '';
	/**
	 * 组件描述
	 *
	 * @memberof ComponentLibraryEntry
	 */
	discription = '';
	/**
	 * 组件图标
	 *
	 * @memberof ComponentLibraryEntry
	 */
	icon = '';
	/**
	 * 组件缩略图
	 *
	 * @memberof ComponentLibraryEntry
	 */
	thumbnail = '';
	/**
	 * 组件作者
	 *
	 * @memberof ComponentLibraryEntry
	 */
	author = '';
	/**
	 * 组件业务分类，如规划、建设、运营等
	 *
	 * @memberof ComponentLibraryEntry
	 */
	classification = '';
	/**
	 * 组件类型，枚举：0（普通组件）、1（容器类组件）
	 *
	 * @memberof ComponentLibraryEntry
	 */
	cpntType = '';
	/**
	 * package 对象包含四个属性: name, url, version, withStylesheet
	 *
	 * @memberof ComponentLibraryEntry
	 */
	package = {
		name: '', // 与moduleName相同
		version: '',
		fileName: '',
		filePath: ''
		// withStylesheet: true,
	};

	/**
	 * @description 组件定义id，同id，因更具语义保留
	 * @memberof ComponentLibraryEntry
	 */
	definitionId = '';
	/**
	 * @description vue组件名称
	 * @memberof ComponentLibraryEntry
	 */
	moduleName = '';
	/**
	 * @description 副作用/关联事件
	 * @memberof ComponentLibraryEntry
	 */
	associatedEvents = '';
	/**
	 * @description 可配置项
	 * @memberof ComponentLibraryEntry
	 */
	configurationItem = '';
	/**
	 * @description 数据型输入
	 * @memberof ComponentLibraryEntry
	 */
	dataInput = '';
	/**
	 * @description 引擎类型
	 * @memberof ComponentLibraryEntry
	 */
	engineType = [];
	/**
	 * @description 交互型输入
	 * @memberof ComponentLibraryEntry
	 */
	interactionInput = '';
	/**
	 * @description 可视化反馈
	 * @memberof ComponentLibraryEntry
	 */
	interactionOutput = '';
	/**
	 * @description 组件更新日期
	 * @memberof ComponentLibraryEntry
	 */
	updateDate = '';
	/**
	 * @description 组件访问次数
	 * @memberof ComponentLibraryEntry
	 */
	visitCounts = '';

	constructor(cpntLibrary) {
		this.id = cpntLibrary.id || '';
		this.definitionId = cpntLibrary.id || '';
		this.name = cpntLibrary.name || cpntLibrary.componentName || '';
		this.moduleName = cpntLibrary.moduleName || cpntLibrary.cpntName;
		this.version = cpntLibrary.version || cpntLibrary.cpntVersion || '';
		this.cpntType = cpntLibrary.cpntType || '';
		this.introduction = cpntLibrary.introduction || cpntLibrary.componentIntroduction || '';
		this.discription = cpntLibrary.discription || cpntLibrary.componentDescription || '';
		this.icon = cpntLibrary.icon || '';
		this.thumbnail = cpntLibrary.thumbnail || cpntLibrary.thumbnailToken || '';
		this.author = cpntLibrary.author || cpntLibrary.developmentResponsible || '';
		this.classification = cpntLibrary.classification || '';

		this.package = cpntLibrary.package || [];

		this.associatedEvents = cpntLibrary.associatedEvents || '';
		this.configurationItem = cpntLibrary.configurationItem || '';
		this.dataInput = cpntLibrary.dataInput || '';
		this.engineType = cpntLibrary.engineType || [];
		this.interactionInput = cpntLibrary.interactionInput || '';
		this.interactionOutput = cpntLibrary.interactionOutput || '';
		this.updateDate = cpntLibrary.updateDate || '';
		this.visitCounts = cpntLibrary.visitCounts || '';
	}
}

export default ComponentLibraryEntry;

export const ComponentLibraryHelper = {
	createAndCacheCpntLibEntry: (cpntLibrary) => {
		const newLibEntry = new ComponentLibraryEntry(cpntLibrary);
		if (cpntLibrary.id && cpntLibrary.package) {
			ComponentLibraryCache[cpntLibrary.id] = newLibEntry;
		}
		return newLibEntry;
	},
	getCpntLibEntryFromCache: (componentDefinitionId) => {
		return ComponentLibraryCache[componentDefinitionId] || null;
	},
	resetLibrary: () => {
		ComponentLibraryCache = {};
	}
};
